<?php
namespace app\admin\model\system;
use think\Model;
use think\facade\Db;
use app\admin\common;
class Department extends Model {
	private $table_obj;
	
	
	public function selectAll($_where,$_field='*',$_order="id desc"){
		extract(common::get('department',[$_where,$_field,__function__]));
		if(empty($data)){
			$_data=Db::name("department")->where($_where)->field($_field)->order($_order)->select();
			if(empty($_data)){
				return [];
			}
			$data=$_data->toArray();
			common::set($data);
		}
		return $data;
	}
	
	public function insertDepartment ($_data) 
	{
		$this->deleteCache('department');
		return Db::name('department')->strict(false)->insert($_data);
	}
	
	public function upDepartment($_up,$_where)
	{
		$this->deleteCache('department');
		return Db::name('department')->where($_where)->update($_up);
	}
	
	public function findDepartment ($_where,$_field)
	{
		extract(common::get('department',[$_where,$_field,__function__]));
		if(empty($data)){
			$data=Db::name("department")->where($_where)->field($_field)->find();
			if(empty($data)){
				return [];
			}
			common::set($data);
		}
		return $data;
	}
	
	/**
	 * @Purpose 删除缓存
	 */
	private function deleteCache($str){
		common::delete($str);	
	}
	
	public function getSql(){
		return Db::name('department')->getLastSql();	
	}
	

}
?>